﻿using Entity.ERP.DTO.PurchaseArriveOrder;
using Entity.ERP.View.PurchaseArriveOrder;
using Entity.ERP.View.PurchaseArriveOrderItem;
using FrameWork.DataHelper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.ERP;

namespace AnQinManagermentBackendAPI.Controller.ERP
{
    /// <summary>
    /// 采购到货单管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class PurchaseArriveOrderController : ControllerBase
    {
        private readonly PurchaseArriveOrderService _purchaseArriveOrderService;

        public PurchaseArriveOrderController(PurchaseArriveOrderService purchaseArriveOrderService)
        {
            _purchaseArriveOrderService = purchaseArriveOrderService;
        }

        /// <summary>
        /// 获取采购到货单列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(PageResult<PurchaseArriveOrderView>), 200)]
        public async Task<IActionResult> GetPurchaseArriveList([FromQuery] PurchaseArriveOrderSearchDTO purchaseArriveOrderSearchDTO)
        {
            var response = await _purchaseArriveOrderService.GetPurchaseArriveList(purchaseArriveOrderSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取采购到货单子单列表
        /// </summary>
        [HttpGet("item")]
        [ProducesResponseType(typeof(PageResult<PurchaseArriveOrderItemView>), 200)]
        public async Task<IActionResult> GetPurchaseArriveOrderItemList([FromQuery] PurchaseArriveOrderItemSearchDTO purchaseArriveOrderItemSearchDTO)
        {
            var response = await _purchaseArriveOrderService.GetPurchaseArriveOrderItemList(purchaseArriveOrderItemSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增采购到货单
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> AddPurchaseArriveOrder([FromBody] PurchaseArriveOrderAddDTO purchaseArriveOrderAddDTO)
        {
            var response = await _purchaseArriveOrderService.AddPurchaseArriveOrder(purchaseArriveOrderAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除采购到货单
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeletePurchaseArriveOrder([FromQuery] string Id)
        {
            var response = await _purchaseArriveOrderService.DeletePurchaseArriveOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核通过采购到货单
        /// </summary>
        [HttpPost("Pass")]
        public async Task<IActionResult> PassPurchaseArriveOrder([FromQuery] string Id)
        {
            var response = await _purchaseArriveOrderService.PassPurchaseArriveOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核不通过采购到货单
        /// </summary>
        [HttpPost("UnPass")]
        public async Task<IActionResult> UnPassPurchaseArriveOrder([FromQuery] string Id)
        {
            var response = await _purchaseArriveOrderService.UnPassPurchaseArriveOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 反审核采购到货单
        /// </summary>
        [HttpPost("CancelPass")]
        public async Task<IActionResult> CancelPassPurchaseArriveOrder([FromQuery] string Id)
        {
            var response = await _purchaseArriveOrderService.CancelPassPurchaseArriveOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 推送
        /// </summary>
        [HttpPost("Push")]
        public async Task<IActionResult> PushPurchaseArriveOrder(string Id)
        {
            var response = await _purchaseArriveOrderService.PushPurchaseArriveOrder(Id);
            return StatusCode(response.Status, response);
        }

    }
}
